{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import csv\n",
    "from tqdm import tqdm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "li_main = [i for i in range(0,67600)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "li_main.insert(0,'label')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|████████████████████████████████████████████████████████████████████████████████| 464/464 [01:10<00:00,  6.54it/s]\n",
      "100%|████████████████████████████████████████████████████████████████████████████████| 751/751 [01:53<00:00,  6.59it/s]\n",
      "  0%|                                                                                          | 0/971 [00:00<?, ?it/s]\n"
     ]
    }
   ],
   "source": [
    "f=open('AD-CN.csv','a')\n",
    "writer = csv.writer(f)\n",
    "writer.writerow(li_main)\n",
    "\n",
    "for folder in os.listdir(\"../../../data/train\"):\n",
    "    for items in tqdm(os.listdir(\"../../../data/train/\" + folder)):\n",
    "        li = []\n",
    "        if folder == 'AD' :\n",
    "            li.append(0)\n",
    "#             break\n",
    "        elif folder == 'MCI' :\n",
    "#             li.append(1)\n",
    "            break\n",
    "        elif folder == 'CN' :\n",
    "            li.append(2)\n",
    "        img = plt.imread(\"../../../data/train/\" + folder + '/' + items)       \n",
    "        li.extend(list(img.flatten()))\n",
    "        writer.writerow(li)\n",
    "        \n",
    "f.flush()\n",
    "f.close()        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\SONAL BANSAL\\Anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py:2728: DtypeWarning: Columns (0) have mixed types. Specify dtype option on import or set low_memory=False.\n",
      "  interactivity=interactivity, compiler=compiler, result=result)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>label</th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>...</th>\n",
       "      <th>67590</th>\n",
       "      <th>67591</th>\n",
       "      <th>67592</th>\n",
       "      <th>67593</th>\n",
       "      <th>67594</th>\n",
       "      <th>67595</th>\n",
       "      <th>67596</th>\n",
       "      <th>67597</th>\n",
       "      <th>67598</th>\n",
       "      <th>67599</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>label</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "      <td>...</td>\n",
       "      <td>67590</td>\n",
       "      <td>67591</td>\n",
       "      <td>67592</td>\n",
       "      <td>67593</td>\n",
       "      <td>67594</td>\n",
       "      <td>67595</td>\n",
       "      <td>67596</td>\n",
       "      <td>67597</td>\n",
       "      <td>67598</td>\n",
       "      <td>67599</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>254</td>\n",
       "      <td>253</td>\n",
       "      <td>254</td>\n",
       "      <td>...</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>254</td>\n",
       "      <td>253</td>\n",
       "      <td>254</td>\n",
       "      <td>...</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>254</td>\n",
       "      <td>253</td>\n",
       "      <td>254</td>\n",
       "      <td>...</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>254</td>\n",
       "      <td>253</td>\n",
       "      <td>254</td>\n",
       "      <td>...</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 67601 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   label    0    1    2    3    4    5    6    7    8  ...    67590  67591  \\\n",
       "0  label    0    1    2    3    4    5    6    7    8  ...    67590  67591   \n",
       "1      2  255  255  255  255  255  255  254  253  254  ...      255    255   \n",
       "2      2  255  255  255  255  255  255  254  253  254  ...      255    255   \n",
       "3      2  255  255  255  255  255  255  254  253  254  ...      255    255   \n",
       "4      2  255  255  255  255  255  255  254  253  254  ...      255    255   \n",
       "\n",
       "   67592  67593  67594  67595  67596  67597  67598  67599  \n",
       "0  67592  67593  67594  67595  67596  67597  67598  67599  \n",
       "1    255    255    255    255    255    255    255    255  \n",
       "2    255    255    255    255    255    255    255    255  \n",
       "3    255    255    255    255    255    255    255    255  \n",
       "4    255    255    255    255    255    255    255    255  \n",
       "\n",
       "[5 rows x 67601 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data=pd.read_csv('AD-CN.csv')\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(data[data['label']==0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████████████████████████████████████████████████████████████████████████████| 80/80 [00:15<00:00,  5.25it/s]\n",
      "100%|████████████████████████████████████████████████████████████████████████████████| 236/236 [00:45<00:00,  5.22it/s]\n",
      "  0%|                                                                                          | 0/295 [00:00<?, ?it/s]\n"
     ]
    }
   ],
   "source": [
    "f=open('AD-CN_val.csv','a')\n",
    "writer = csv.writer(f)\n",
    "writer.writerow(li_main)\n",
    "for folder in os.listdir(\"../../../data/val\"):\n",
    "    for items in tqdm(os.listdir(\"../../../data/val/\" + folder)):\n",
    "        li = []\n",
    "        if folder == 'AD' :\n",
    "            li.append(0)\n",
    "            \n",
    "#             break\n",
    "        elif folder == 'MCI' :\n",
    "#             li.append(1)\n",
    "            break\n",
    "        elif folder == 'CN' :\n",
    "            li.append(2)\n",
    "        img = plt.imread(\"../../../data/val/\" + folder + '/' + items)       \n",
    "        li.extend(list(img.flatten()))\n",
    "        writer.writerow(li)\n",
    "f.flush()\n",
    "f.close()        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>label</th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>...</th>\n",
       "      <th>67590</th>\n",
       "      <th>67591</th>\n",
       "      <th>67592</th>\n",
       "      <th>67593</th>\n",
       "      <th>67594</th>\n",
       "      <th>67595</th>\n",
       "      <th>67596</th>\n",
       "      <th>67597</th>\n",
       "      <th>67598</th>\n",
       "      <th>67599</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>254</td>\n",
       "      <td>253</td>\n",
       "      <td>254</td>\n",
       "      <td>...</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>254</td>\n",
       "      <td>253</td>\n",
       "      <td>254</td>\n",
       "      <td>...</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>254</td>\n",
       "      <td>253</td>\n",
       "      <td>254</td>\n",
       "      <td>...</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>254</td>\n",
       "      <td>253</td>\n",
       "      <td>254</td>\n",
       "      <td>...</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>254</td>\n",
       "      <td>253</td>\n",
       "      <td>254</td>\n",
       "      <td>...</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "      <td>255</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 67601 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   label    0    1    2    3    4    5    6    7    8  ...    67590  67591  \\\n",
       "0      2  255  255  255  255  255  255  254  253  254  ...      255    255   \n",
       "1      2  255  255  255  255  255  255  254  253  254  ...      255    255   \n",
       "2      2  255  255  255  255  255  255  254  253  254  ...      255    255   \n",
       "3      2  255  255  255  255  255  255  254  253  254  ...      255    255   \n",
       "4      2  255  255  255  255  255  255  254  253  254  ...      255    255   \n",
       "\n",
       "   67592  67593  67594  67595  67596  67597  67598  67599  \n",
       "0    255    255    255    255    255    255    255    255  \n",
       "1    255    255    255    255    255    255    255    255  \n",
       "2    255    255    255    255    255    255    255    255  \n",
       "3    255    255    255    255    255    255    255    255  \n",
       "4    255    255    255    255    255    255    255    255  \n",
       "\n",
       "[5 rows x 67601 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_val=pd.read_csv('AD-CN_val.csv')\n",
    "data_val.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
